package algorithm;

public class leetcode_0135 {
    public int candy(int[] ratings) {
        int len=ratings.length;
        int[] result=new int[len];
        result[0]=1;
        for(int i=1;i<len;++i){
            if(ratings[i]>ratings[i-1]) result[i]=result[i-1]+1;
            else result[i]=1;
        }
        for(int i=len-2;i>=0;--i){
            if(ratings[i]>ratings[i+1]) result[i]=Math.max(result[i],result[i+1]+1 );
        }
        int sum=0;
        for(int i=0;i<len;++i){
            sum+=result[i];
        }
        return sum;
    }
}
